package com.hucheng.rest.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hucheng.activity.query.LuckPrizeQuery;
import com.hucheng.activity.service.LuckPrizeService;
import com.hucheng.activity.vo.LuckPrizeVO;
import com.hucheng.activity.vo.PrizeVO;
import com.hucheng.common.exception.EduException;
import com.hucheng.common.page.CommonPager;
import com.hucheng.common.page.PageParameter;
import com.hucheng.common.response.ServiceCoreVO;
import com.hucheng.common.utils.ValidatorUtils;
import com.hucheng.rest.base.BaseAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-10
 * @Description: 抽奖Api
 **/
@Slf4j
@Controller("luckPrizeAction")
public class LuckPrizeAction extends BaseAction{

    @Reference
    private LuckPrizeService luckPrizeService;

    /**
     * 抽奖列表
     *
     * @return
     * @throws EduException
     */
    public ServiceCoreVO listV100() throws EduException {

        String currentPage = getRequestContentValue("currentPage");
        String pageSize = getRequestContentValue("pageSize");

        PageParameter pageParameter = new PageParameter();
        if (currentPage != null && !currentPage.equals("null") &&
                pageSize != null && !pageSize.equals("null")) {
            pageParameter = new PageParameter(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
        }

        LuckPrizeQuery luckPrizeQuery = new LuckPrizeQuery();
        luckPrizeQuery.setPageParameter(pageParameter);
        CommonPager<LuckPrizeVO> commonPager = luckPrizeService.list(luckPrizeQuery);

        return response(commonPager);
    }

    /**
     * 抽奖
     * @return
     * @throws EduException
     */
    public ServiceCoreVO luckPrizeV100() throws EduException {

        String luckPrizeId = getRequestContentValue("luck_prize_id");

        if(ValidatorUtils.isEmpty(luckPrizeId)){
            throw new EduException(140003);
        }

        PrizeVO prizeVO = luckPrizeService.luckPrize(userId,Integer.parseInt(luckPrizeId));

        return response(prizeVO);
    }

}
